﻿using System;
using System.IO;
using System.Threading.Tasks;
using System.Xml.Serialization;

public static class EE_Data
{
        public const int minGoldCollect = 10;
        public enum BuildingID
        {
                townhall,goldmine,goldstorage,elixer,elixerstorage
        }
        public class Building
        {
                public long tableId;
                public BuildingID id = BuildingID.townhall;
                public int level = 1;
                public int x = 0;
                public int y = 0;
                public int rows = 1;
                public int cols = 1;
                public int storage = 0;
                public int capacity = 0;
                public DateTime boost;
                public bool constructing = false;// 是否正在建造
                public int upgradeCostSeconds = 12;
                public DateTime constructionTime;// 建造完成时间
        }
        
        public async static Task<string> Serialize<T>(T target)
        {
                Task<string> task = Task.Run((() =>
                {
                        XmlSerializer xml = new XmlSerializer(typeof(T));
                        StringWriter writer = new StringWriter();
                        xml.Serialize(writer, target);
                        return writer.ToString();
                }));
                return await task;
        }

        public async static Task<T> Deserialize<T>(string target)
        {
                Task<T> task = Task.Run((() =>
                {
                        XmlSerializer xml = new XmlSerializer(typeof(T));
                        StringReader reader = new StringReader(target);
                        return (T)xml.Deserialize(reader);
                }));
                return await task;
        }
}